package Demo;
//用栈模拟队列的实现
//我们统一规定，入队，就入s1,出队就在s2中出
//出之前我们需要判断s1,s2的情况，都为空，出不了。s2为空，就把s1中所有元素放入s2中，再出，不为空，直接出
import java.util.Stack;

public class MyQueue {
    Stack<Integer> s1;
    Stack<Integer> s2;
    public MyQueue(){
        s1=new Stack<>();
        s2=new Stack<>();
    }
    public void push(int x){
        s1.push(x);
    }
    public int pop(){
        if (Empty()){
            return -1;
        }
        if (s2.isEmpty()){
           int size=s1.size();
           while (size!=0){
               int val=s1.pop();
               s2.push(val);
           }
        }
            return s2.pop();

    }
    public int peek(){
        if (Empty()){
            return -1;
        }
        if (s2.isEmpty()){
            int size=s1.size();
            while (size!=0){
                int val=s1.pop();
                s2.push(val);
            }
            return s2.peek();
        }
        else {
            return s2.peek();
        }
    }
    public boolean Empty(){
        return s1.isEmpty()&& s2.isEmpty();
    }
}
